package com.gridmobi.xrtb.routers.bidding;

import com.alibaba.fastjson.JSONObject;
import com.gridmobi.xrtb.domain.dsp.DspTrackLog;
import com.gridmobi.xrtb.dspcounter.DspCounterHandler;
import com.gridmobi.xrtb.util.RtbUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.time.LocalDateTime;
import java.util.Map;

/**
 * 到达率统计接收URL
 */
@RestController
@RequestMapping("/")
public class ClickLandController {

    private static final Logger logger = LoggerFactory.getLogger(ClickLandController.class);
    private static final Logger clicklog = LoggerFactory.getLogger("clicklog");
    private static final Logger errorlogger = LoggerFactory.getLogger("error");
    @Autowired
    DspCounterHandler dspCounterHandler;


    @GetMapping("dspddl")
    public void click(@RequestParam Map<String, String> args, HttpServletRequest request, HttpServletResponse response) {
        try {
            LocalDateTime now = LocalDateTime.now();
            DspTrackLog trackArgs = RtbUtil.packTrackArgs(now, args, request);
            if(trackArgs.getCid()==null){
                trackArgs.setCid(request.getParameter("cid"));
            }
//            biddingLogger.landlog(trackArgs);
        } catch (Exception e) {
            errorlogger.error("landerror:".concat(JSONObject.toJSONString(args)), e);
        }
        clicklog.warn("myland:" + JSONObject.toJSONString(args));

    }
}
